package dialogs.example;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.os.Bundle;

public class DialogsExamplesActivity extends Activity {
    private static final int DIALOG_ALERT = 0;
	private static final int DIALOG_PROGRESS = 1;

	/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }
    
    /**
     * Crea los diálogos
     */
   @Override
   protected Dialog onCreateDialog(int id) {
	   Dialog newDialog = null;
	   switch (id) {
	   	case DIALOG_ALERT:
	   		AlertDialog.Builder builder = new AlertDialog.Builder(this);
	   		builder.setMessage("¿Quieres salir?");
	   		builder.setCancelable(false);
	   		builder.setPositiveButton("Si", new DialogInterface.OnClickListener() {
	   			public void onClick(DialogInterface dialog, int id) {
	   				DialogsExamplesActivity.this.finish();
	   			}});
	   		builder.setNegativeButton("No", new DialogInterface.OnClickListener() {
	   			public void onClick(DialogInterface dialog, int id) {
	   				dialog.cancel();
	   			}});
	   		newDialog = builder.create();
	   		break;
	   	case DIALOG_PROGRESS:
	   		newDialog = ProgressDialog.show(DialogsExamplesActivity.this, "", "Cargando, espere...", true);
	   		break;
	   }
	   return newDialog;
   }
}